package com.huage.courseplatform.application.service.impl;

import com.huage.courseplatform.application.mapper.BusinessMapper;
import com.huage.courseplatform.application.mapper.TeacherMapper;
import com.huage.courseplatform.application.model.entity.Business;
import com.huage.courseplatform.application.model.entity.Teacher;
import com.huage.courseplatform.application.service.ApplyAccountService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import static com.huage.courseplatform.framework.constant.StatusConstants.ACCOUNT_REVIEW;

@Service
public class ApplyAccountServiceImpl implements ApplyAccountService {
    @Resource
    BusinessMapper businessMapper;

    @Resource
    TeacherMapper teacherMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    @CacheEvict(cacheNames = "Service:BusinessService:page", allEntries=true)
    public void applyBusiness(String userId, Business business) {
        //状态定义为：审核中
        business.setStatus(ACCOUNT_REVIEW);
        businessMapper.insert(business);
        //添加对应关系
        businessMapper.insertUserBusinessById(userId,business.getId());

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @CacheEvict(cacheNames = "Service:TeacherService:page", allEntries=true)
    public void applyTeacher(String userId, Teacher teacher) {
        //状态定义为：审核中
        teacher.setStatus(ACCOUNT_REVIEW);
        teacherMapper.insert(teacher);
        //添加对应关系
        teacherMapper.insertUserTeacherById(userId,teacher.getId());
    }


}
